package service;

import URL.Constants;
import bean.Block;
import com.alibaba.fastjson.JSONObject;
import requerst.HttpUtils;

import java.util.Base64;
import java.util.HashMap;
import java.util.Map;

public class GetDifficulty {
/**
 * @author: dae
 * @email: 675116529@qq.com
 * @phone: 15270029507
 * @DateTime: 2021/12/22 19:38
 *getdifficulty
 **/

public String getDifficulty() {
    //准备rpc请求的用户身份信息
    String author = Constants.buser + ":" + Constants.bpwd;
    Base64.Encoder encoder = Base64.getEncoder();
    String authorBase64 = encoder.encodeToString(author.getBytes());
    Map<String, String> header = new HashMap<>();
    header.put("ContentType", "application/json");
    header.put("Authorization", "Basic " + authorBase64);
    //准备rpc请求的数据`
    Map<String, Object> body = new HashMap<>();
    body.put("id", 1001);
    body.put("method", "getdifficulty");
    body.put("params", null);
    body.put("json_rpc", "2.0");
    byte[] bodyBytes = JSONObject.toJSONBytes(body);

    String result = HttpUtils.post(Constants.brpc_url, header, bodyBytes);
    Block block = JSONObject.parseObject(result, Block.class);
    return block.result;


}


}
